//
//  ClassifyViewController.m
//  JZMCFM
//
//  Created by Mc on 15/10/30.
//  Copyright (c) 2015年 陈卓. All rights reserved.
//

#import "ClassifyViewController.h"
#import "ClassifyHelper.h"
#import "CategoryTableViewCell.h"
#import "CategoryModel.h"
#import "CategoryDetailViewController.h"

static NSString *cell_id = @"CategoryTableViewCell.h";

@interface ClassifyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *categoryTableView;

@end

@implementation ClassifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置代理
    self.categoryTableView.dataSource = self;
    self.categoryTableView.delegate = self;
    
    //注册cell
    [self.categoryTableView registerNib:[UINib nibWithNibName:@"CategoryTableViewCell" bundle:nil] forCellReuseIdentifier:cell_id];
    
    //调用解析方法
    [[ClassifyHelper sharedInstance]downLoadDataFinished:^{
        [self.categoryTableView reloadData];
    }];
    
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [ClassifyHelper sharedInstance].categoryArray.count ;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CategoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id forIndexPath:indexPath];

    CategoryModel *model = [ClassifyHelper sharedInstance].categoryArray[indexPath.row];
    [cell setCellDataWithModel:model];
    return cell;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 65;
}


#pragma mark cell的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CategoryDetailViewController *cdVC = [[CategoryDetailViewController alloc]init];
    cdVC.index = indexPath.row;
    [self.navigationController pushViewController:cdVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
